import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useStore = defineStore('pinia_store', () => {
  const cityName = ref('')
  const cityId = ref(0)
  const pageNum = ref(1)
  const pageSize = ref(10)
  const tabIndex = ref(0) // 0: 正在热映 1:即将上映
  const playingFilms = ref([])
  const playingTotal = ref(0)
  const upcomingFilms = ref([])
  const upcomingTotal = ref(0)
  const cinemas = ref([])
  const cinemasTotal = ref(0)


  // 手动实现 $reset 方法
  const $reset = () => {
    cinemas.value = [];
    cinemasTotal.value = 0;
    // cityName.value = '北京';
    // cityId.value = 110100;
    pageNum.value = 1;
    pageSize.value = 10;
    tabIndex.value = 0;
    playingFilms.value = [];
    playingTotal.value = 0;
    upcomingFilms.value = [];
    upcomingTotal.value = 0;
  };


  const setCinemas = (cinemaList) => {
    cinemas.value = cinemaList
  }

  const setCinemasTotal = (num) => {
    cinemasTotal.value = num
  }


  const setCityName = (name) => {
    cityName.value = name
  }

  const setCityId = (id) => {
    cityId.value = id
  }

  const setPageNum = (num) => {
    pageNum.value = num
  }
  const setPageSize = (size) => {
    pageSize.value = size
  }
  const setTabIndex = (index) => {
    tabIndex.value = index
  }
  const setPlayingFilms = (films) => {
    playingFilms.value = films
  }
  const setPlayingTotal = (total) => {
    playingTotal.value = total
  }
  const setUpcomingFilms = (films) => {
    upcomingFilms.value = films
  }
  const setUpcomingTotal = (total) => {
    upcomingTotal.value = total
  }
  return {
    cinemas,
    cinemasTotal,
    cityName,
    cityId,
    pageNum,
    pageSize,
    tabIndex,
    playingFilms,
    playingTotal,
    upcomingFilms,
    upcomingTotal,
    setCinemas,
    setCinemasTotal,
    setCityName,
    setCityId,
    setPageNum,
    setPageSize,
    setTabIndex,
    setPlayingFilms,
    setPlayingTotal,
    setUpcomingFilms,
    setUpcomingTotal,
    $reset, // 添加 $reset 方法
  }
}, {
  persist: true, // 持久化存储
},)
